<template>
	<view class="appraise">
		<view class="grade">
			<view v-show="!rateValue">点击星星评分</view>
			<view v-show="rateValue==1">很差</view>
			<view v-show="rateValue==2">较差</view>
			<view v-show="rateValue==3">还行</view>
			<view v-show="rateValue==4">推荐</view>
			<view v-show="rateValue==5">力荐</view>
			<uni-rate touchable v-model="rateValue"></uni-rate>
		</view>
		<uni-easyinput type="textarea" v-model="review" placeholder="说说看过之后的感受吧" placeholderStyle="font-size:15px;"
					   trim="both" :clearable="false"></uni-easyinput>
		<button class="post" hover-class="posted" @click="post()">发布</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				uid: 0,
				movie_id: 0,
				rateValue: 0,
				review: ''
			}
		},
		onLoad(options) {
			this.movie_id = options.movie_id
			this.uid = options.uid
		},
		methods: {
			post() {
				if(this.review.length!=0&&this.rateValue!=0){
					uni.request({
						url: 'http://www.yingke.com/Index/addReview',
						data:{
							grade: this.rateValue,
							uid: this.uid,
							movie_id: this.movie_id,
							content: this.review
						},
						method: 'POST',
						success: () => {
							uni.showToast({
								icon: 'none',
								title: '发布成功',
							});
							setTimeout(() => {
								uni.hideToast();
								//关闭提示后跳转
								let pages = getCurrentPages();
								let beforePage = pages[pages.length - 2];
								beforePage.$vm.reFresh = Math.random()
								uni.navigateBack();
							},1500)
						}
					})
				}	
				else
					uni.showToast({
						title: '请点击评分并输入评论内容',
						icon: 'none'
					})
			}
		}
	}
</script>

<style lang="scss">
	.appraise{
		.grade{
			text-align: center;
			vertical-align: middle;
			color: #C0C0C0;
		}
		.post{
			width: 75%;
			background: #d81e06;
			color: #fff;
		}
		.posted{
			background: #bf1202;
		}
	}
</style>
